﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellConsoleCommand_h
#define CellConsoleCommand_h

#include "CellAppPrerequisites.h"

namespace cell
{
/** \addtogroup Core
 *  @{
 */
/** \addtogroup General
 *  @{
 */

/** 控制台命令。
@author
	Jiangwei Xu
*/
class ConsoleCommand : public GeneralAlloc
{
public:
	/** 默认构造函数。
	*/
	ConsoleCommand(const String& name, const String& desc, const String& usage);

	/** 析构函数。
	*/
	virtual ~ConsoleCommand(void);

public:
	/** 命令状态。
	*/
	typedef enum _State
	{
		/// 正在执行。
		CCS_EXECUTING = 1,

		/// 结束命令。
		CCS_FINISHED
	} State;

	/** 返回命令名。
	*/
	const String& name(void) const;

	/** 返回命令描述信息。
	*/
	const String& description(void) const;

	/** 返回命令使用说明。
	*/
	const String& usage(void) const;

	/** 向终端打印指定信息。
	*/
	void print(const String& text);
	/** 向终端打印指定信息，并将游标移动到下一行。
	*/
	void println(const String& text);
	/** 向终端打印指定信息，并将游标移动到下一行。
	*/
	void println(char* text);

public:
	/** 执行命令。
	*/
	virtual bool execute(const String& args = "") = 0;

	/** 命令状态。
	*/
	virtual State state(void) = 0;

	/** 处理交互输入信息。
	*/
	virtual void input(const String& input) = 0;

protected:
	String mName;
	String mDescription;
	String mUsage;
};


/** 未知命令。
*/
class UnknownCommand : public ConsoleCommand
{
public:
	/**
	*/
	UnknownCommand(void);

	/**
	*/
	virtual ~UnknownCommand(void);

public:
	/**
	*/
	bool execute(const String& args);

	/**
	*/
	ConsoleCommand::State state(void);

	/**
	*/
	void input(const String& input);
};

/** @} */
/** @} */
} // end namespace cell

#endif // CellConsoleCommand_h
